<?php
/**
 * 
 */
use Fox\SalesDistribution\Sales;
use Custom\Control;
$today = new DateTime();
$today->sub(new DateInterval("P1M"));
$finder = new Control();
$res = $finder->find(new Fox\Dao\SqlFragment("uname = ? ",array(User::current()->getId())),
					array("date" => "DESC"),
					null,
					1);
$action = "fm_gen_save('?mod=controlling&act=month&sac=approve&approved=true',null,null,'hide(\'copVal\')')";

if(count($res) > 0)
{

	$date = new DateTime($res[0]->date);
	if($today->format("mY") == $date->format("mY"))
	{
		// Month has already been validated
		$popup = new Fox\Popup\Info("pxValidation",
									"Valider le mois",
									Msg(Sales::BUNDLE_NAME,34,$today->format("m"),$today->format("Y")),
									300);
	}
	else
	{

		$popup = new Fox\Popup\ToConfirm("pValidation",
									 "Valider le mois",
									 Msg(Sales::BUNDLE_NAME,33,$today->format("m"),$today->format("Y")),
									 $action);
	}
}
else
{
	$popup = new Fox\Popup\ToConfirm("pValidation",
									 "Valider le mois",
									 Msg(Sales::BUNDLE_NAME,33,$today->format("m"),$today->format("Y")),
									 $action);
}

echo $popup->display();